package cn.zkc.library.dao;

import cn.zkc.library.modal.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Mapper
@Component(value = "UserDAO" )
public interface UserDAO {

    String table_name = "user";
    String insert_field = "name, password, email";
    String select_field ="id, name, password, email";

    @Insert({"insert into", table_name, "(", insert_field, ") value (#{name}, #{password}, #{email})"})
    int addUser(User user);

    @Select({"select", select_field, "from", table_name, "where id=#{id}"})
    User selectById(int id);

    @Select({"select", select_field, "from", table_name, "where name=#{name}"})
    User selectByName(String name);

    @Select({"select", select_field, "from", table_name, "where email=#{email}"})
    User selectByEmail(String email);

    @Update({"update", table_name, "set password=#{password} where id=#{id}"})
    void updatePassword(User user);

}
